package zhklappoint.initsys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import zhklappoint.ZhklAppointApplication;
import zhklappoint.enums.ENUM_SUCESS;
import zhklappoint.util.ResponseBean;

@Configuration
@ComponentScan(basePackageClasses = ZhklAppointApplication.class, useDefaultFilters = true)
public class MiddleInterceptors extends HandlerInterceptorAdapter {

	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		String userAgent = request.getHeader("user-agent").toLowerCase();
//		System.out.println("userAgent:"+userAgent);
			if(userAgent.indexOf("micromessenger")!= -1){ 
//				System.out.println("微信");
			//微信 
			}else if(userAgent.indexOf("android") != -1){ 
				//安卓
//				System.out.println("安卓");
			}else if(userAgent.indexOf("iphone") != -1 || userAgent.indexOf("ipad") != -1 || userAgent.indexOf("ipod") != -1){
					//苹果 
//				System.out.println("苹果 ");
				}else{
					//电脑 
//					System.out.println("电脑 ");
//					return false;
					}
		return true;
	}
}
